﻿import Request from '../../base/request.js?t=202511041006'
import Storage from '../../base/storage.js?t=202511041006'
import { dealTime, imageBaseUrl, IgetDeptList, getRecentYears, getMonthList, getBrowserInfo } from "../../base/utils.js?t=202511041006"
const Composition = (proxy) => {

    const generateh = (text, isShort) => {
        if (isShort) {
            return h('div', {
                style: "width:100px;overflow:hidden;white-space: nowrap;text-overflow: ellipsis; -o-text-overflow: ellipsis;cursor:pointer"
            }, { default: () => text })
        } else {
            return h('div', {
                style: "width:300px;height:auto;"
            }, { default: () => text })
        }

    }

    const data = reactive({
        messageTest: "",
        proxy: "",
        cIndex: 1,
        tabList: [],
        queryParams: {
            year: null,
            month: null,
            dept: null,
        },
        Ids: [],
        plform: {

        },
        opType: true,
        plOpen: false,
        pagination: {
            total: 0,
            current: 1,
            pageSize: 10,
            loading: true,
            showTotal: total => `总共 ${total} 项`,
            defaultPageSize: 10,
            // pageSizeOptions: ['5', '10', '15', '20'], // 可不设置使用默认
            showSizeChanger: true, // 是否显示pagesize选择
            showQuickJumper: false, // 是否显示跳转窗
        },
        deptList: [

        ],

        yearList: [

        ],
        monthList: [

        ],
        columns1: [
            {
                title: '序号',
                dataIndex: 'a',
                key: 'a',
                align: 'center',
                width: 80,
                customRender: ({ index }) => {
                    return (params.pagination.value.current - 1) * params.pagination.value.pageSize + index + 1
                },
            },

            {
                title: '年份',
                dataIndex: 'Years',
                key: 'Years',
                align: 'center',

            },
            {
                title: '考核月份',
                dataIndex: 'Months',
                key: 'Months',
                align: 'center',
                customRender: ({ text }) => {
                    return text + '月'
                },
            },
            {
                title: '部门',
                dataIndex: 'DepartmentName',
                key: 'DepartmentName',
                align: 'center'
            },
            {
                title: '分值',
                dataIndex: 'TotalScore',
                key: 'TotalScore',
                align: 'center',
                sorter: (a, b) => {
                    return a.TotalScore - b.TotalScore
                },
                customRender: function ({ text }) {
                    return (Math.floor(+text * Math.pow(10, 2)) / Math.pow(10, 2)).toFixed(2)
                }
            },
            {
                title: '日期',
                dataIndex: 'UpdateTime',
                key: 'UpdateTime',
                align: 'center',
                customRender: function ({ text }) {
                    return dealTime(text, 'YYYY-MM-DD')
                }
            },
            {
                title: '状态',
                dataIndex: 'StatusName',
                key: 'StatusName',
                align: 'center',
                customRender: function ({ text, record, index, column }) {
                    return h(antd.Tag, {
                        color: text == '保存' ? "#87d068" : "#108ee9",
                    }, { default: () => text });
                }
            },
            {
                title: '审核人数量',
                dataIndex: 'ApproverCount',
                key: 'ApproverCount',
                align: 'center',

                customRender: function ({ text, record, index, column }) {

                    let content = h('div', {
                        style: 'width:700px'
                    }, { default: () => record.ApproverCount.map(e => e).join('、 ') });




                    let textc = h(antd.Button, {
                        type: "link"
                    }, { default: () => record.ApproverCount.length });

                    return record.ApproverCount.length == 0 ? h(antd.Space, {
                        //title: '审核人姓名',
                        //content: content,

                    }, () => [textc]) : h(antd.Popover, {
                        title: '审核人姓名',
                        content: content,

                    }, () => [textc]);
                }



            },
            {
                title: '操作',
                key: 'action',
                align: 'center',
                customRender: function ({ text, record, index, column }) {

                    let editBtn = h(antd.Button, {
                        style: record.Status == 0 ? '' : 'display:none',
                        type: "link",
                        onClick: () => methods.handleEdit(record.Id, true)
                    }, { default: () => '编辑' })



                    let checkBtn = h(antd.Button, {
                        style: record.IsApprover == true ? '' : 'display:none',
                        type: "link",
                        onClick: () => methods.handleMCheck(record.Id)
                    }, { default: () => '审批' })

                    let returnBtn = h(antd.Button, {
                        style: record.IsWithDraw == false ? 'display:none' : '',
                        type: "link",

                    }, { default: () => '撤回' })
                    let detailBtn = h(antd.Button, {
                        style: '',
                        type: "link",
                        onClick: () => methods.handleEdit(record.Id, false)
                    }, { default: () => '详情' })

                    let publicBtn = h(antd.Button, {
                        style: record.Status == 0 ? '' : 'display:none',

                        type: "link"
                    }, { default: () => '提交' })

                    const fPublicBtn = h(antd.Popconfirm, {
                        title: "确定提交此数据？",
                        onConfirm: () => methods.handlePublick(record.Id)

                    }, { default: () => publicBtn })


                    const fReturnBtn = h(antd.Popconfirm, {
                        title: "确定撤回此数据？",
                        onConfirm: () => methods.handleReturn(record.Id)

                    }, { default: () => returnBtn })


                    let delBtn = h(antd.Button, {
                        style: 'margin-right:4px',
                        type: "link"
                    }, { default: () => '删除' })

                    const fDelBtn = h(antd.Popconfirm, {
                        title: "确定删除此数据？",
                        onConfirm: () => methods.handleDelete(record.Id)

                    }, { default: () => delBtn })


                    return h(antd.Space, {
                    },
                        { default: () => [editBtn, fReturnBtn, detailBtn, fPublicBtn, fDelBtn, checkBtn] }
                    );

                }
            },
        ],
        columns2: [
            {
                title: '序号',
                dataIndex: 'a',
                key: 'a',
                align: 'center',
                width: 80,
                customRender: ({ index }) => {
                    return (params.pagination.value.current - 1) * params.pagination.value.pageSize + index + 1
                },
            },
            {
                title: '考核标题',
                dataIndex: 'PlanNoticeName',
                key: 'PlanNoticeName',
                align: 'center'

            },
            {
                title: '提交部门',
                dataIndex: 'DepartmentName',
                key: 'DepartmentName',
                align: 'center'
            },
            {
                title: '自评总分',
                dataIndex: 'SelfTotalScore',
                key: 'SelfTotalScore',
                align: 'center'
            },
            {
                title: '考评总分',
                dataIndex: 'ActualTotalScore',
                key: 'ActualTotalScore',
                align: 'center',
                customRender: ({ text }) => {
                    return text || '-'
                },
            },
            {
                title: '提交人',
                dataIndex: 'UserName',
                key: 'UserName',
                align: 'center'
            },

            {
                title: '状态',
                dataIndex: 'StatusName',
                key: 'StatusName',
                align: 'center',
                customRender: function ({ text }) {
                    return h(antd.Tag, {
                        color: text == '办结' ? "#87d068" : "#108ee9"
                    }, { default: () => text });
                }
            },
            {
                title: '备注',
                dataIndex: 'Remark',
                key: 'Remark',
                align: 'center'
            },
            {
                title: '操作',
                key: 'action',
                align: 'center',
                customRender: function ({ text, record, index, column }) {

                    let checkBtn = h(antd.Button, {
                        style: record.IsApprover ? '' : 'display:none',
                        type: "link",

                        onClick: () => {
                            methods.handleCheck(record.Id)
                        }
                    }, { default: () => '审核' })


                    let evaluateBtn = h(antd.Button, {
                        style: record.IsEvalution ? '' : 'display:none',
                        type: "link",
                        onClick: () => {
                            methods.handleEvaluate(record.Id)
                        }
                    }, { default: () => '考评' })

                    let approvalBtn = h(antd.Button, {
                        style: record.IsRatify ? '' : 'display:none',
                        type: "link",
                        onClick: () => {
                            methods.handleApproval(record.Id)
                        }
                    }, { default: () => '批准' })


                    let detailBtn = h(antd.Button, {

                        type: "link",
                        onClick: () => {
                            methods.handleDetail(record.Id)
                        }
                    }, { default: () => '详情' })
                    let editBtn = h(antd.Button, {

                        type: "link",
                        onClick: () => {
                            methods.handleyEdit(record.Id)
                        }
                    }, { default: () => '编辑' })

                    return h(antd.Space, {
                    },
                        { default: () => [checkBtn, evaluateBtn, approvalBtn, detailBtn, editBtn] }
                    );

                }
            },
        ],
        columns3: [
            {
                title: '序号',
                dataIndex: 'a',
                key: 'a',
                align: 'center',
                width: 80,
                customRender: ({ index }) => {
                    return (params.pagination.value.current - 1) * params.pagination.value.pageSize + index + 1
                },
            },
            {
                title: '年度',
                dataIndex: 'a',
                key: 'a',
                align: 'center'

            },
            {
                title: '部门',
                dataIndex: 'b',
                key: 'b',
                align: 'center'
            },
            {
                title: '月度总分值',
                dataIndex: 'c',
                key: 'c',
                align: 'center'
            },
            {
                title: '年度总分值',
                dataIndex: 'd',
                key: 'd',
                align: 'center'
            },
            {
                title: '实际总分值',
                dataIndex: 'e',
                key: 'e',
                align: 'center',
                sorter: (a, b) => a.e - b.e,
            },

        ],

        dataSource1: [],
        dataSource2: [],
        dataSource3: [],
    })
    let params = toRefs(data)
    const methods = {
        tchange: (e) => {
            methods.getTableList(true)
            params.queryParams.value = {

            }
        },
        handleOk: () => {
            console.log(params.Ids.value)
            Request({
                url: "/performance/ApproveMonthReport",
                method: 'post',
                data: {
                    FormId: params.Ids.value,
                    "IsApprove": params.opType.value,
                    "Remark": params.plform.value.Remark
                },
            }).then(res => {
                params.messageTest.value.info(res.Msg);
                methods.getTableList(true)
                params.plOpen.value = false
            })



        },
        plSubmit: (status) => {
            params.opType.value = status
            params.plOpen.value = true

        },
        rowSelection: {
            onChange: (selectedRowKeys, selectedRows) => {
                console.log(selectedRowKeys, 'selectedRowKeys')
                params.Ids.value = selectedRowKeys

            },
            getCheckboxProps: record => ({
                disabled: record.Status == 0 || record.Status == 2,

            })
        },
        filterOption: (val, type) => {
            console.log(type)

            return `${type.label}`.includes(`${val || ''}`)
        },
        handlePublick: (id) => {
            Request({
                url: "/performance/PublishMonthReport",
                method: 'post',
                params: {
                    FormId: id
                },
            }).then(res => {
                params.messageTest.value.info(res.Msg);
                methods.getTableList(true)
            })
        },
        handleDelete: (id) => {
            Request({
                url: "/performance/DeleteMonthReport",
                method: 'post',
                params: {
                    FormId: id
                },

            }).then(res => {
                params.messageTest.value.info(res.Msg);
                methods.getTableList(true)

            })
        },
        handleMCheck: (id) => {


            window.location.href = `/Performance/PerformanceAssessCheck?type=0&id=${id}&isEdit=${false}`
        },
        handleReturn: (id) => {
            Request({
                url: "/performance/WithdrawMonthReport",
                method: 'post',
                params: {
                    FormId: id
                },

            }).then(res => {
                params.messageTest.value.info(res.Msg);
                methods.getTableList(true)

            })
        },
        handleEdit: (id, isEdit = true) => {
            window.location.href = `/Performance/PerformanceAddAssess?type=0&id=${id}&isEdit=${isEdit}`
        },
        fillInfo: () => {
            if (params.cIndex.value == 0) {
                window.location.href = '/Performance/PerformanceAddAssess?type=0'
            }
            else {
                window.location.href = '/Performance/PerformanceAddAssess?type=1'
            }
        },
        handleTableChange: (page) => {
            const { current, pageSize } = page
            params.pagination.value.current = current;
            params.pagination.value.pageSize = pageSize;
            methods.getTableList()
        },
        handleApproval: (id) => {
            window.location.href = `/Performance/PerformanceMeansApproval?id=${id}`
        },
        handleCheck: (id) => {
            window.location.href = `/Performance/PerformanceMeansCheck?id=${id}`
        },
        handleDetail: (id) => {
            window.location.href = `/Performance/PerformanceMeansDetail?id=${id}`
        },
        handleyEdit: (id) => {
            window.location.href = `/Performance/PerformanceAddAssess?type=1&id=${id}`
        },
        handleEvaluate: (id) => {
            window.location.href = `/Performance/PerformanceMeansEvaluate?id=${id}`
        },
        getTableList: async (isRresh) => {

            if (isRresh) {
                params.pagination.value.current = 1
            }
            params.pagination.value.loading = true
            if (params.cIndex.value == 0) {
                let res = await IgetDeptList(Request)
                params.deptList.value = res


                Request({
                    url: "/performance/GetMonthReportPageList",
                    method: 'post',
                    params: {
                        page: params.pagination.value.current,
                        pageSize: params.pagination.value.pageSize
                    },
                    data: {
                        "DepartmentId": params.queryParams.value.dept,
                        "Years": params.queryParams.value.year,
                        "Month": params.queryParams.value.month
                    }
                }).then(res => {


                    params.dataSource1.value = res.Data.Data
                    params.pagination.value.total = res.Data.TotalItemCount
                    params.pagination.value.loading = false
                })





            }

            if (params.cIndex.value == 1) {
                Request({
                    url: "/performance/GetYearsReportPageList",
                    method: 'post',
                    params: {
                        page: params.pagination.value.current,
                        pageSize: params.pagination.value.pageSize
                    },
                    data: {
                        //Years: params.queryParams.value.year,
                        //TypeId: params.cIndex.value,
                        //CategoryId: params.formState2.value.CategoryId
                    }
                }).then(res => {
                    //params.messageTest.value.info(res.Msg);

                    params.dataSource2.value = res.Data.Data
                    params.pagination.value.total = res.Data.TotalItemCount
                    params.pagination.value.loading = false
                })

            }
            if (params.cIndex.value == 2) {


            }



        },

        tt: () => {
            window.location.href = '/Performance/PerformanceDeptSetting'
        },
        init: () => {
            getBrowserInfo().catch(err => { console.log(err) })
            if (proxy) {
                params.proxy.value = proxy
            }
            params.yearList.value = getRecentYears()
            params.monthList.value = getMonthList()
            const { message } = antd
            params.messageTest.value = message
            params.messageTest.value.config({
                top: `10vh`,
                duration: 7,
                maxCount: 1,
                rtl: true,
            });

            setTimeout(() => {
                let info = Storage.get('AccountInfo', true)
                if (info && info.DepartmentId == 20) {
                    params.cIndex.value = 1
                    params.tabList.value = [{ label: "年度考核", value: 1 }, { label: "月度考核", value: 0 }]

                } else {
                    params.cIndex.value = 1
                    params.tabList.value = [{ label: "年度考核", value: 1 }]

                }




                Request({
                    url: "/Account/createJwtToken",
                    method: 'post',
                    data: {
                        "userName": info && info.UserNo
                    }
                }).then(res => {
                    Storage.set('token', res.Data,true)

                    /// performance / GetYearsReportPageList
                    methods.getTableList(true)


                })
            }, 400)





            params.dataSource1.value = [

            ]


            params.dataSource2.value = [

            ],
                params.dataSource3.value = [
                    {
                        a: '2024', b: '公司办公室', c: '59', d: "30", e: '80',
                    }, {
                        a: '2024', b: '发展规划部', c: '59', d: "30", e: '78',
                    }, {
                        a: '2024', b: '财务部', c: '59', d: "33", e: '77',
                    },
                ]
        },

    }



    const template = {
        test: {
            template: `<div @click="add">+</div> <div>{{testnum}}</div>`,

            setup() {

                return {
                    ...params,
                    ...methods,
                };
            }

        }
    }
    return {
        ...params,
        ...methods,
        template
    }
}

export default Composition